export default class Scanner {
    constructor(templateStr) {
        this.templateStr = templateStr;
        this.pos = 0;
        this.tail = templateStr;
    }

    scan(stopTag) {
        if (this.tail.indexOf(stopTag) === 0) {
            this.pos += stopTag.length;
            this.tail = this.templateStr.substring(this.pos);
        }
    }

    scanUtil(stopTag) {
        const index = this.tail.indexOf(stopTag);
        const posBackup = this.pos;

        this.pos = index === -1
            ? this.pos + this.tail.length
            : this.pos + index;

        this.tail = this.templateStr.substring(this.pos);

        return this.templateStr.substring(posBackup, this.pos);
    }

    eos() {
        return this.templateStr.length > this.pos;
    }
}